#!/usr/bin/env python

"""
    Fov.py
    This file contains FOV procedures
"""

# Imports
from math import *

class rayCast(object):
    def __init__(self, gameUI, gameMap, gameObjects, pc, radius):
        self.gameUI = gameUI
        self.gameMap = gameMap
        self.gameObjects = gameObjects
        self.pc = pc
        self.radius = radius
        self.rad2 = radius * radius

    def computeFov(self):
        for y in range(self.gameMap.height):
            for x in range(self.gameMap.width):
                self.gameMap.map[y][x].fov = False


        for i in range(360):
            x = cos(i * 0.01745)
            y = sin(i * 0.01745)

            self.ox = self.pc.posx + 0.5
            self.oy = self.pc.posy + 0.5

            self.block = False

            while (((self.ox - self.pc.posx)*(self.ox - self.pc.posx) + (self.oy - self.pc.posy)*(self.oy - self.pc.posy)) < self.rad2) and self.ox >= 0 and self.ox < self.gameMap.width and self.oy >= 0 and self.oy < self.gameMap.height:
                if self.block == False:
                    self.gameMap.map[int(self.oy)][int(self.ox)].fov = True
                    self.gameMap.map[int(self.oy)][int(self.ox)].visited = True
                if self.gameMap.map[int(self.oy)][int(self.ox)].block_los == True:
                    self.block = True

                self.ox += x
                self.oy += y